//
//  ScanCollectionCell.m
//  FKGW
//
//  Created by song ce on 2017/2/18.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "ScanCollectionCell.h"
#import "UIView+Extend.h"
#import "OSSHelper.h"
#import "AppDelegate.h"
#import "UIImage+ScaleImge.h"
@implementation ScanCollectionCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

-(void)setScanModel:(QickScanModel *)scanModel{
    _scanModel = scanModel;
//    self.isNeedPriceLabel = _scanModel.isNeedPriceLabel;
    [self setNeedsLayout];
}

-(void)layoutSubviews{
    UIImage *image = [[UIImage alloc]initWithContentsOfFile:_scanModel.pic];
    if(image.size.width>Main_Screen_Width){
        image = [self scaleImage:image toScale:(float)Main_Screen_Width/image.size.width];
    }
  
    self.imageV.frame =CGRectMake(0, 0, Main_Screen_Width, image.size.height);
    self.imageV.centerY = self.centerY;
    self.imageV.image = image;
    
//    self.imageV.contentMode =UIViewContentModeScaleAspectFill;
//    self.priceLabel.text = [NSString stringWithFormat:@"￥ %@",_scanModel.price];
}

- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
    UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize));
    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height * scaleSize)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}


- (UIImageView *)imageV{
    DLog(@"--是否需要价格标签----%d",self.isNeedPriceLabel);
    if(!_imageV){
        _imageV = [[UIImageView alloc]init];
        [self addSubview:_imageV];
//        if(self.isNeedPriceLabel){
//            UIImageView  *priceImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
//            priceImageV.image = [UIImage imageNamed:@"biaoqian_nor"];
//            [self.imageV addSubview:priceImageV];
//            self.priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, (priceImageV.height)/2-18, priceImageV.width-20, 20)];
//            self.priceLabel.font = [UIFont systemFontOfSize:16];
//            self.priceLabel.textColor = DEF_COLOR102;
//            self.priceLabel.textAlignment = NSTextAlignmentCenter;
//            [_imageV addSubview:self.priceLabel];
//            self.priceLabel.transform = CGAffineTransformMakeRotation(-M_PI_4);
//        }
    }
    return  _imageV;
}


@end
